#pragma once

#include <vector>

#include "FixedSizeAllocator2.h"


namespace MemMgr
{
	class SmallObjectAllocator2
	{
	public:

		SmallObjectAllocator2(size_t iPageSize, size_t iMaxObjectSize);

		void* Allocate(size_t iNumBytes);
		void Deallocate(void* iPtr, size_t iSize);

	private:

		SmallObjectAllocator2(const SmallObjectAllocator2& iOther); // Not implemented
		SmallObjectAllocator2& operator=(const SmallObjectAllocator2& iOther); // Not implemented

		inline size_t RetrieveId(const AtomSizeU iNumBytes) const;

		typedef size_t FixedSizeAllocatorId;
		typedef std::vector<FixedSizeAllocatorId> PoolId;
		typedef std::vector<FixedSizeAllocator2> Pool;

		static const T_U16 MAX_ID_NUM = static_cast<T_U16>(~0);
		static const T_U16 NUM_BIT_ALIGNMENT = 16;
		static const T_U16 LOG2_NUM_BIT_ALIGNMENT = 5;

		PoolId mPoolId;
		Pool mPool;
		size_t mPageSize;
		size_t mMaxObjectSize;
	};



	inline size_t SmallObjectAllocator2::RetrieveId(const AtomSizeU iNumBytes) const
	{
		return (iNumBytes + NUM_BIT_ALIGNMENT-1) >> LOG2_NUM_BIT_ALIGNMENT;
	}
}